package com.pingxx.boot.demo.controller;

import com.pingxx.boot.demo.req.UserRegisterReq;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("user")
public class UserController {


    @PostMapping("register")
    public String register(@Valid @RequestBody UserRegisterReq req, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            String msg = "";
            for (ObjectError error : bindingResult.getAllErrors()) {
                msg += error.getDefaultMessage() + "|";
            }
            return msg;
        }
        return "Hello Boot";
    }
}
